
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
  <head>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Base views &#8212; Django 1.11.22.dev20190603194737 documentation</title>
    <link rel="stylesheet" href="../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <script type="text/javascript" src="../../_static/language_data.js"></script>
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" />
    <link rel="next" title="Generic display views" href="generic-display.html" />
    <link rel="prev" title="Built-in class-based views API" href="index.html" />



 
<script type="text/javascript" src="../../templatebuiltins.js"></script>
<script type="text/javascript">
(function($) {
    if (!django_template_builtins) {
       // templatebuiltins.js missing, do nothing.
       return;
    }
    $(document).ready(function() {
        // Hyperlink Django template tags and filters
        var base = "../templates/builtins.html";
        if (base == "#") {
            // Special case for builtins.html itself
            base = "";
        }
        // Tags are keywords, class '.k'
        $("div.highlight\\-html\\+django span.k").each(function(i, elem) {
             var tagname = $(elem).text();
             if ($.inArray(tagname, django_template_builtins.ttags) != -1) {
                 var fragment = tagname.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + tagname + "</a>");
             }
        });
        // Filters are functions, class '.nf'
        $("div.highlight\\-html\\+django span.nf").each(function(i, elem) {
             var filtername = $(elem).text();
             if ($.inArray(filtername, django_template_builtins.tfilters) != -1) {
                 var fragment = filtername.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + filtername + "</a>");
             }
        });
    });
})(jQuery);
</script>


  </head><body>

    <div class="document">
  <div id="custom-doc" class="yui-t6">
    <div id="hd">
      <h1><a href="../../index.html">Django 1.11.22.dev20190603194737 documentation</a></h1>
      <div id="global-nav">
        <a title="Home page" href="../../index.html">Home</a>  |
        <a title="Table of contents" href="../../contents.html">Table of contents</a>  |
        <a title="Global index" href="../../genindex.html">Index</a>  |
        <a title="Module index" href="../../py-modindex.html">Modules</a>
      </div>
      <div class="nav">
    &laquo; <a href="index.html" title="Built-in class-based views API">previous</a>
     |
    <a href="../index.html" title="API Reference" accesskey="U">up</a>
   |
    <a href="generic-display.html" title="Generic display views">next</a> &raquo;</div>
    </div>

    <div id="bd">
      <div id="yui-main">
        <div class="yui-b">
          <div class="yui-g" id="ref-class-based-views-base">
            
  <div class="section" id="s-base-views">
<span id="base-views"></span><h1>Base views<a class="headerlink" href="#base-views" title="Permalink to this headline">¶</a></h1>
<p>The following three classes provide much of the functionality needed to create
Django views. You may think of them as <em>parent</em> views, which can be used by
themselves or inherited from. They may not provide all the capabilities
required for projects, in which case there are Mixins and Generic class-based
views.</p>
<p>Many of Django’s built-in class-based views inherit from other class-based
views or various mixins. Because this inheritance chain is very important, the
ancestor classes are  documented under the section title of <strong>Ancestors (MRO)</strong>.
MRO is an acronym for Method Resolution Order.</p>
<div class="section" id="s-view">
<span id="view"></span><h2><code class="docutils literal notranslate"><span class="pre">View</span></code><a class="headerlink" href="#view" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="django.views.generic.base.View">
<em class="property">class </em><code class="descclassname">django.views.generic.base.</code><code class="descname">View</code><a class="headerlink" href="#django.views.generic.base.View" title="Permalink to this definition">¶</a></dt>
<dd><p>The master class-based base view. All other class-based views inherit from
this base class. It isn’t strictly a generic view and thus can also be
imported from <code class="docutils literal notranslate"><span class="pre">django.views</span></code>.</p>
<div class="versionchanged">
<span class="title">Changed in Django 1.10:</span> <p>The ability to import from <code class="docutils literal notranslate"><span class="pre">django.views</span></code> was added.</p>
</div>
<p><strong>Method Flowchart</strong></p>
<ol class="arabic simple">
<li><a class="reference internal" href="#django.views.generic.base.View.dispatch" title="django.views.generic.base.View.dispatch"><code class="xref py py-meth docutils literal notranslate"><span class="pre">dispatch()</span></code></a></li>
<li><a class="reference internal" href="#django.views.generic.base.View.http_method_not_allowed" title="django.views.generic.base.View.http_method_not_allowed"><code class="xref py py-meth docutils literal notranslate"><span class="pre">http_method_not_allowed()</span></code></a></li>
<li><a class="reference internal" href="#django.views.generic.base.View.options" title="django.views.generic.base.View.options"><code class="xref py py-meth docutils literal notranslate"><span class="pre">options()</span></code></a></li>
</ol>
<p><strong>Example views.py</strong>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">django.http</span> <span class="k">import</span> <span class="n">HttpResponse</span>
<span class="kn">from</span> <span class="nn">django.views</span> <span class="k">import</span> <span class="n">View</span>

<span class="k">class</span> <span class="nc">MyView</span><span class="p">(</span><span class="n">View</span><span class="p">):</span>

    <span class="k">def</span> <span class="nf">get</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">HttpResponse</span><span class="p">(</span><span class="s1">&#39;Hello, World!&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p><strong>Example urls.py</strong>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">django.conf.urls</span> <span class="k">import</span> <span class="n">url</span>

<span class="kn">from</span> <span class="nn">myapp.views</span> <span class="k">import</span> <span class="n">MyView</span>

<span class="n">urlpatterns</span> <span class="o">=</span> <span class="p">[</span>
    <span class="n">url</span><span class="p">(</span><span class="sa">r</span><span class="s1">&#39;^mine/$&#39;</span><span class="p">,</span> <span class="n">MyView</span><span class="o">.</span><span class="n">as_view</span><span class="p">(),</span> <span class="n">name</span><span class="o">=</span><span class="s1">&#39;my-view&#39;</span><span class="p">),</span>
<span class="p">]</span>
</pre></div>
</div>
<p><strong>Attributes</strong></p>
<dl class="attribute">
<dt id="django.views.generic.base.View.http_method_names">
<code class="descname">http_method_names</code><a class="headerlink" href="#django.views.generic.base.View.http_method_names" title="Permalink to this definition">¶</a></dt>
<dd><p>The list of HTTP method names that this view will accept.</p>
<p>Default:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">[</span><span class="s1">&#39;get&#39;</span><span class="p">,</span> <span class="s1">&#39;post&#39;</span><span class="p">,</span> <span class="s1">&#39;put&#39;</span><span class="p">,</span> <span class="s1">&#39;patch&#39;</span><span class="p">,</span> <span class="s1">&#39;delete&#39;</span><span class="p">,</span> <span class="s1">&#39;head&#39;</span><span class="p">,</span> <span class="s1">&#39;options&#39;</span><span class="p">,</span> <span class="s1">&#39;trace&#39;</span><span class="p">]</span>
</pre></div>
</div>
</dd></dl>

<p><strong>Methods</strong></p>
<dl class="classmethod">
<dt id="django.views.generic.base.View.as_view">
<em class="property">classmethod </em><code class="descname">as_view</code>(<em>**initkwargs</em>)<a class="headerlink" href="#django.views.generic.base.View.as_view" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a callable view that takes a request and returns a response:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">response</span> <span class="o">=</span> <span class="n">MyView</span><span class="o">.</span><span class="n">as_view</span><span class="p">()(</span><span class="n">request</span><span class="p">)</span>
</pre></div>
</div>
<p>The returned view has <code class="docutils literal notranslate"><span class="pre">view_class</span></code> and <code class="docutils literal notranslate"><span class="pre">view_initkwargs</span></code>
attributes.</p>
<p>When the view is called during the request/response cycle, the
<a class="reference internal" href="../request-response.html#django.http.HttpRequest" title="django.http.HttpRequest"><code class="xref py py-class docutils literal notranslate"><span class="pre">HttpRequest</span></code></a> is assigned to the view’s <code class="docutils literal notranslate"><span class="pre">request</span></code>
attribute. Any positional and/or keyword arguments <a class="reference internal" href="../../topics/http/urls.html#how-django-processes-a-request"><span class="std std-ref">captured from
the URL pattern</span></a> are assigned to the
<code class="docutils literal notranslate"><span class="pre">args</span></code> and <code class="docutils literal notranslate"><span class="pre">kwargs</span></code> attributes, respectively. Then <a class="reference internal" href="#django.views.generic.base.View.dispatch" title="django.views.generic.base.View.dispatch"><code class="xref py py-meth docutils literal notranslate"><span class="pre">dispatch()</span></code></a>
is called.</p>
</dd></dl>

<dl class="method">
<dt id="django.views.generic.base.View.dispatch">
<code class="descname">dispatch</code>(<em>request</em>, <em>*args</em>, <em>**kwargs</em>)<a class="headerlink" href="#django.views.generic.base.View.dispatch" title="Permalink to this definition">¶</a></dt>
<dd><p>The <code class="docutils literal notranslate"><span class="pre">view</span></code> part of the view – the method that accepts a <code class="docutils literal notranslate"><span class="pre">request</span></code>
argument plus arguments, and returns a HTTP response.</p>
<p>The default implementation will inspect the HTTP method and attempt to
delegate to a method that matches the HTTP method; a <code class="docutils literal notranslate"><span class="pre">GET</span></code> will be
delegated to <code class="docutils literal notranslate"><span class="pre">get()</span></code>, a <code class="docutils literal notranslate"><span class="pre">POST</span></code> to <code class="docutils literal notranslate"><span class="pre">post()</span></code>, and so on.</p>
<p>By default, a <code class="docutils literal notranslate"><span class="pre">HEAD</span></code> request will be delegated to <code class="docutils literal notranslate"><span class="pre">get()</span></code>.
If you need to handle <code class="docutils literal notranslate"><span class="pre">HEAD</span></code> requests in a different way than <code class="docutils literal notranslate"><span class="pre">GET</span></code>,
you can override the <code class="docutils literal notranslate"><span class="pre">head()</span></code> method. See
<a class="reference internal" href="../../topics/class-based-views/index.html#supporting-other-http-methods"><span class="std std-ref">Supporting other HTTP methods</span></a> for an example.</p>
</dd></dl>

<dl class="method">
<dt id="django.views.generic.base.View.http_method_not_allowed">
<code class="descname">http_method_not_allowed</code>(<em>request</em>, <em>*args</em>, <em>**kwargs</em>)<a class="headerlink" href="#django.views.generic.base.View.http_method_not_allowed" title="Permalink to this definition">¶</a></dt>
<dd><p>If the view was called with a HTTP method it doesn’t support, this
method is called instead.</p>
<p>The default implementation returns <code class="docutils literal notranslate"><span class="pre">HttpResponseNotAllowed</span></code> with a
list of allowed methods in plain text.</p>
</dd></dl>

<dl class="method">
<dt id="django.views.generic.base.View.options">
<code class="descname">options</code>(<em>request</em>, <em>*args</em>, <em>**kwargs</em>)<a class="headerlink" href="#django.views.generic.base.View.options" title="Permalink to this definition">¶</a></dt>
<dd><p>Handles responding to requests for the OPTIONS HTTP verb. Returns a
response with the <code class="docutils literal notranslate"><span class="pre">Allow</span></code> header containing a list of the view’s
allowed HTTP method names.</p>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="s-templateview">
<span id="templateview"></span><h2><code class="docutils literal notranslate"><span class="pre">TemplateView</span></code><a class="headerlink" href="#templateview" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="django.views.generic.base.TemplateView">
<em class="property">class </em><code class="descclassname">django.views.generic.base.</code><code class="descname">TemplateView</code><a class="headerlink" href="#django.views.generic.base.TemplateView" title="Permalink to this definition">¶</a></dt>
<dd><p>Renders a given template, with the context containing parameters captured
in the URL.</p>
<p><strong>Ancestors (MRO)</strong></p>
<p>This view inherits methods and attributes from the following views:</p>
<ul class="simple">
<li><a class="reference internal" href="mixins-simple.html#django.views.generic.base.TemplateResponseMixin" title="django.views.generic.base.TemplateResponseMixin"><code class="xref py py-class docutils literal notranslate"><span class="pre">django.views.generic.base.TemplateResponseMixin</span></code></a></li>
<li><a class="reference internal" href="mixins-simple.html#django.views.generic.base.ContextMixin" title="django.views.generic.base.ContextMixin"><code class="xref py py-class docutils literal notranslate"><span class="pre">django.views.generic.base.ContextMixin</span></code></a></li>
<li><a class="reference internal" href="#django.views.generic.base.View" title="django.views.generic.base.View"><code class="xref py py-class docutils literal notranslate"><span class="pre">django.views.generic.base.View</span></code></a></li>
</ul>
<p><strong>Method Flowchart</strong></p>
<ol class="arabic simple">
<li><a class="reference internal" href="#django.views.generic.base.View.dispatch" title="django.views.generic.base.View.dispatch"><code class="xref py py-meth docutils literal notranslate"><span class="pre">dispatch()</span></code></a></li>
<li><a class="reference internal" href="#django.views.generic.base.View.http_method_not_allowed" title="django.views.generic.base.View.http_method_not_allowed"><code class="xref py py-meth docutils literal notranslate"><span class="pre">http_method_not_allowed()</span></code></a></li>
<li><a class="reference internal" href="mixins-simple.html#django.views.generic.base.ContextMixin.get_context_data" title="django.views.generic.base.ContextMixin.get_context_data"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_context_data()</span></code></a></li>
</ol>
<p><strong>Example views.py</strong>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">django.views.generic.base</span> <span class="k">import</span> <span class="n">TemplateView</span>

<span class="kn">from</span> <span class="nn">articles.models</span> <span class="k">import</span> <span class="n">Article</span>

<span class="k">class</span> <span class="nc">HomePageView</span><span class="p">(</span><span class="n">TemplateView</span><span class="p">):</span>

    <span class="n">template_name</span> <span class="o">=</span> <span class="s2">&quot;home.html&quot;</span>

    <span class="k">def</span> <span class="nf">get_context_data</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="n">context</span> <span class="o">=</span> <span class="nb">super</span><span class="p">(</span><span class="n">HomePageView</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">get_context_data</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="n">context</span><span class="p">[</span><span class="s1">&#39;latest_articles&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">Article</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">all</span><span class="p">()[:</span><span class="mi">5</span><span class="p">]</span>
        <span class="k">return</span> <span class="n">context</span>
</pre></div>
</div>
<p><strong>Example urls.py</strong>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">django.conf.urls</span> <span class="k">import</span> <span class="n">url</span>

<span class="kn">from</span> <span class="nn">myapp.views</span> <span class="k">import</span> <span class="n">HomePageView</span>

<span class="n">urlpatterns</span> <span class="o">=</span> <span class="p">[</span>
    <span class="n">url</span><span class="p">(</span><span class="sa">r</span><span class="s1">&#39;^$&#39;</span><span class="p">,</span> <span class="n">HomePageView</span><span class="o">.</span><span class="n">as_view</span><span class="p">(),</span> <span class="n">name</span><span class="o">=</span><span class="s1">&#39;home&#39;</span><span class="p">),</span>
<span class="p">]</span>
</pre></div>
</div>
<p><strong>Context</strong></p>
<ul class="simple">
<li>Populated (through <a class="reference internal" href="mixins-simple.html#django.views.generic.base.ContextMixin" title="django.views.generic.base.ContextMixin"><code class="xref py py-class docutils literal notranslate"><span class="pre">ContextMixin</span></code></a>) with
the keyword arguments captured from the URL pattern that served the view.</li>
</ul>
</dd></dl>

</div>
<div class="section" id="s-redirectview">
<span id="redirectview"></span><h2><code class="docutils literal notranslate"><span class="pre">RedirectView</span></code><a class="headerlink" href="#redirectview" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="django.views.generic.base.RedirectView">
<em class="property">class </em><code class="descclassname">django.views.generic.base.</code><code class="descname">RedirectView</code><a class="headerlink" href="#django.views.generic.base.RedirectView" title="Permalink to this definition">¶</a></dt>
<dd><p>Redirects to a given URL.</p>
<p>The given URL may contain dictionary-style string formatting, which will be
interpolated against the parameters captured in the URL. Because keyword
interpolation is <em>always</em> done (even if no arguments are passed in), any
<code class="docutils literal notranslate"><span class="pre">&quot;%&quot;</span></code> characters in the URL must be written as <code class="docutils literal notranslate"><span class="pre">&quot;%%&quot;</span></code> so that Python
will convert them to a single percent sign on output.</p>
<p>If the given URL is <code class="docutils literal notranslate"><span class="pre">None</span></code>, Django will return an <code class="docutils literal notranslate"><span class="pre">HttpResponseGone</span></code>
(410).</p>
<p><strong>Ancestors (MRO)</strong></p>
<p>This view inherits methods and attributes from the following view:</p>
<ul class="simple">
<li><a class="reference internal" href="#django.views.generic.base.View" title="django.views.generic.base.View"><code class="xref py py-class docutils literal notranslate"><span class="pre">django.views.generic.base.View</span></code></a></li>
</ul>
<p><strong>Method Flowchart</strong></p>
<ol class="arabic simple">
<li><a class="reference internal" href="#django.views.generic.base.View.dispatch" title="django.views.generic.base.View.dispatch"><code class="xref py py-meth docutils literal notranslate"><span class="pre">dispatch()</span></code></a></li>
<li><a class="reference internal" href="#django.views.generic.base.View.http_method_not_allowed" title="django.views.generic.base.View.http_method_not_allowed"><code class="xref py py-meth docutils literal notranslate"><span class="pre">http_method_not_allowed()</span></code></a></li>
<li><a class="reference internal" href="#django.views.generic.base.RedirectView.get_redirect_url" title="django.views.generic.base.RedirectView.get_redirect_url"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_redirect_url()</span></code></a></li>
</ol>
<p><strong>Example views.py</strong>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">django.shortcuts</span> <span class="k">import</span> <span class="n">get_object_or_404</span>
<span class="kn">from</span> <span class="nn">django.views.generic.base</span> <span class="k">import</span> <span class="n">RedirectView</span>

<span class="kn">from</span> <span class="nn">articles.models</span> <span class="k">import</span> <span class="n">Article</span>

<span class="k">class</span> <span class="nc">ArticleCounterRedirectView</span><span class="p">(</span><span class="n">RedirectView</span><span class="p">):</span>

    <span class="n">permanent</span> <span class="o">=</span> <span class="kc">False</span>
    <span class="n">query_string</span> <span class="o">=</span> <span class="kc">True</span>
    <span class="n">pattern_name</span> <span class="o">=</span> <span class="s1">&#39;article-detail&#39;</span>

    <span class="k">def</span> <span class="nf">get_redirect_url</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="n">article</span> <span class="o">=</span> <span class="n">get_object_or_404</span><span class="p">(</span><span class="n">Article</span><span class="p">,</span> <span class="n">pk</span><span class="o">=</span><span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;pk&#39;</span><span class="p">])</span>
        <span class="n">article</span><span class="o">.</span><span class="n">update_counter</span><span class="p">()</span>
        <span class="k">return</span> <span class="nb">super</span><span class="p">(</span><span class="n">ArticleCounterRedirectView</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">get_redirect_url</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
</pre></div>
</div>
<p><strong>Example urls.py</strong>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">django.conf.urls</span> <span class="k">import</span> <span class="n">url</span>
<span class="kn">from</span> <span class="nn">django.views.generic.base</span> <span class="k">import</span> <span class="n">RedirectView</span>

<span class="kn">from</span> <span class="nn">article.views</span> <span class="k">import</span> <span class="n">ArticleCounterRedirectView</span><span class="p">,</span> <span class="n">ArticleDetail</span>

<span class="n">urlpatterns</span> <span class="o">=</span> <span class="p">[</span>
    <span class="n">url</span><span class="p">(</span><span class="sa">r</span><span class="s1">&#39;^counter/(?P&lt;pk&gt;[0-9]+)/$&#39;</span><span class="p">,</span> <span class="n">ArticleCounterRedirectView</span><span class="o">.</span><span class="n">as_view</span><span class="p">(),</span> <span class="n">name</span><span class="o">=</span><span class="s1">&#39;article-counter&#39;</span><span class="p">),</span>
    <span class="n">url</span><span class="p">(</span><span class="sa">r</span><span class="s1">&#39;^details/(?P&lt;pk&gt;[0-9]+)/$&#39;</span><span class="p">,</span> <span class="n">ArticleDetail</span><span class="o">.</span><span class="n">as_view</span><span class="p">(),</span> <span class="n">name</span><span class="o">=</span><span class="s1">&#39;article-detail&#39;</span><span class="p">),</span>
    <span class="n">url</span><span class="p">(</span><span class="sa">r</span><span class="s1">&#39;^go-to-django/$&#39;</span><span class="p">,</span> <span class="n">RedirectView</span><span class="o">.</span><span class="n">as_view</span><span class="p">(</span><span class="n">url</span><span class="o">=</span><span class="s1">&#39;https://djangoproject.com&#39;</span><span class="p">),</span> <span class="n">name</span><span class="o">=</span><span class="s1">&#39;go-to-django&#39;</span><span class="p">),</span>
<span class="p">]</span>
</pre></div>
</div>
<p><strong>Attributes</strong></p>
<dl class="attribute">
<dt id="django.views.generic.base.RedirectView.url">
<code class="descname">url</code><a class="headerlink" href="#django.views.generic.base.RedirectView.url" title="Permalink to this definition">¶</a></dt>
<dd><p>The URL to redirect to, as a string. Or <code class="docutils literal notranslate"><span class="pre">None</span></code> to raise a 410 (Gone)
HTTP error.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.views.generic.base.RedirectView.pattern_name">
<code class="descname">pattern_name</code><a class="headerlink" href="#django.views.generic.base.RedirectView.pattern_name" title="Permalink to this definition">¶</a></dt>
<dd><p>The name of the URL pattern to redirect to. Reversing will be done
using the same args and kwargs as are passed in for this view.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.views.generic.base.RedirectView.permanent">
<code class="descname">permanent</code><a class="headerlink" href="#django.views.generic.base.RedirectView.permanent" title="Permalink to this definition">¶</a></dt>
<dd><p>Whether the redirect should be permanent. The only difference here is
the HTTP status code returned. If <code class="docutils literal notranslate"><span class="pre">True</span></code>, then the redirect will use
status code 301. If <code class="docutils literal notranslate"><span class="pre">False</span></code>, then the redirect will use status code
302. By default, <code class="docutils literal notranslate"><span class="pre">permanent</span></code> is <code class="docutils literal notranslate"><span class="pre">False</span></code>.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.views.generic.base.RedirectView.query_string">
<code class="descname">query_string</code><a class="headerlink" href="#django.views.generic.base.RedirectView.query_string" title="Permalink to this definition">¶</a></dt>
<dd><p>Whether to pass along the GET query string to the new location. If
<code class="docutils literal notranslate"><span class="pre">True</span></code>, then the query string is appended to the URL. If <code class="docutils literal notranslate"><span class="pre">False</span></code>,
then the query string is discarded. By default, <code class="docutils literal notranslate"><span class="pre">query_string</span></code> is
<code class="docutils literal notranslate"><span class="pre">False</span></code>.</p>
</dd></dl>

<p><strong>Methods</strong></p>
<dl class="method">
<dt id="django.views.generic.base.RedirectView.get_redirect_url">
<code class="descname">get_redirect_url</code>(<em>*args</em>, <em>**kwargs</em>)<a class="headerlink" href="#django.views.generic.base.RedirectView.get_redirect_url" title="Permalink to this definition">¶</a></dt>
<dd><p>Constructs the target URL for redirection.</p>
<p>The default implementation uses <a class="reference internal" href="#django.views.generic.base.RedirectView.url" title="django.views.generic.base.RedirectView.url"><code class="xref py py-attr docutils literal notranslate"><span class="pre">url</span></code></a> as a starting
string and performs expansion of <code class="docutils literal notranslate"><span class="pre">%</span></code> named parameters in that string
using the named groups captured in the URL.</p>
<p>If <a class="reference internal" href="#django.views.generic.base.RedirectView.url" title="django.views.generic.base.RedirectView.url"><code class="xref py py-attr docutils literal notranslate"><span class="pre">url</span></code></a> is not set, <code class="docutils literal notranslate"><span class="pre">get_redirect_url()</span></code> tries to reverse the
<a class="reference internal" href="#django.views.generic.base.RedirectView.pattern_name" title="django.views.generic.base.RedirectView.pattern_name"><code class="xref py py-attr docutils literal notranslate"><span class="pre">pattern_name</span></code></a> using what was captured in the URL (both named and
unnamed groups are used).</p>
<p>If requested by <a class="reference internal" href="#django.views.generic.base.RedirectView.query_string" title="django.views.generic.base.RedirectView.query_string"><code class="xref py py-attr docutils literal notranslate"><span class="pre">query_string</span></code></a>, it will also append the query
string to the generated URL.
Subclasses may implement any behavior they wish, as long as the method
returns a redirect-ready URL string.</p>
</dd></dl>

</dd></dl>

</div>
</div>


          </div>
        </div>
      </div>
      
        
          <div class="yui-b" id="sidebar">
            
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../../contents.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Base views</a><ul>
<li><a class="reference internal" href="#view"><code class="docutils literal notranslate"><span class="pre">View</span></code></a></li>
<li><a class="reference internal" href="#templateview"><code class="docutils literal notranslate"><span class="pre">TemplateView</span></code></a></li>
<li><a class="reference internal" href="#redirectview"><code class="docutils literal notranslate"><span class="pre">RedirectView</span></code></a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="index.html"
                        title="previous chapter">Built-in class-based views API</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="generic-display.html"
                        title="next chapter">Generic display views</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../../_sources/ref/class-based-views/base.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
              <h3>Last update:</h3>
              <p class="topless">Jun 03, 2019</p>
          </div>
        
      
    </div>

    <div id="ft">
      <div class="nav">
    &laquo; <a href="index.html" title="Built-in class-based views API">previous</a>
     |
    <a href="../index.html" title="API Reference" accesskey="U">up</a>
   |
    <a href="generic-display.html" title="Generic display views">next</a> &raquo;</div>
    </div>
  </div>

      <div class="clearer"></div>
    </div>
  </body>
</html>